package red.sms.db.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import red.sms.db.config.DBConfig;
 
public class ConnectionFactory {
    private static Connection con;
    public static DBConfig dbc = new DBConfig();
    
    @SuppressWarnings("static-access")
	private ConnectionFactory()throws Exception{
    	dbc.loadProperties();
        Class.forName("com.mysql.jdbc.Driver");
        String dburl=dbc.db_url;
        String username=dbc.db_account;
        String password=dbc.db_password;
        con=DriverManager.getConnection(dburl,username,password);
    }
    
    public static ConnectionFactory getInstance()throws Exception{
        return new ConnectionFactory();
    }
 
    public Connection getConnection(){
        return con;
    }
    public void closeConnection()throws Exception{
        if(con!=null)
            con.close();
    }
}
